package org.zcl;

import org.dom4j.DocumentException;
import org.junit.Test;
import org.zcl.entity.User;
import org.zcl.io.Resource;
import org.zcl.sqlSession.SqlSession;
import org.zcl.sqlSession.SqlSessionFactory;
import org.zcl.sqlSession.SqlSessionFactoryBuilder;

import java.beans.IntrospectionException;
import java.beans.PropertyVetoException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;

/**
 * .
 *
 * @Author Chenglin Zhu
 * @Date 2022/3/12 17:34
 */
public class IPersistence {

    @Test
    public void test() throws DocumentException, PropertyVetoException, SQLException, ClassNotFoundException, IntrospectionException, NoSuchFieldException, InvocationTargetException, IllegalAccessException, InstantiationException {
        InputStream resourceAsStream = Resource.getResourceAsStream("sqlMapperConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
       /* User user = new User();
        user.setId(1);
        user.setUsername("赵雷");
        User result = sqlSession.selectOne("user.selectOne", user);
        System.out.println(result);*/

        List<User> users = sqlSession.selectList("user.selectList");
        System.out.println(Arrays.toString(users.toArray()));
    }

    @Test
    public void testDao() throws Exception {
       /* InputStream resourceAsStream = Resource.getResourceAsStream("sqlMapperConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserDao userDao = sqlSession.getMapper(UserDao.class);

        User user = new User();
        user.setId(1);
        user.setUsername("赵雷");
        User po = userDao.findOne(user);
        System.out.println(po);

        List<User> users = userDao.findAll();
        System.out.println(Arrays.toString(users.toArray()));*/
    }
}
